import type { FormRules } from "element-plus";

// 定义 validate1验证器
export const validate1 = (
  rule: FormRules,
  value: string,
  callback: (error?: Error) => void
): void => {
  const regex = /^[a-zA-Z0-9_]+$/;
  if (!regex.test(value)) {
    callback(new Error("请输入大小写字母、数字和下划线"));
  } else {
    callback();
  }
};

export const validate2 = (
  rule: FormRules,
  value: string,
  callback: (error?: Error) => void
): void => {
  let regex = /^[\u4e00-\u9fa5a-zA-Z0-9 \（\）\@\-\_()]+$/;
  if (!regex.test(value)) {
    callback(new Error("请输入中文、英文字母、数字、和特殊字符_-@()"));
  } else {
    callback();
  }
};



export function validateWhitespace (str) {
  const reg = /^\s+|\s+$/
  return reg.test(str)
}